<template>
  <div class="reportFormPage" v-if="show">
    <div class="report-dom">
      <el-row>
        <el-col :span="5" :offset="19">
          <div class="pageNumBox">
            <span>第</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.page }}&nbsp;</span>
            <span>页，共</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.totalPage }}&nbsp;</span>
            <span>页</span>
          </div>
        </el-col>
      </el-row>
      <div class="topTwoBox">
        <div class="centerName">{{ this.form.baobmc }}</div>
        <div class="codeText">
          <tr v-for="(item, index) in form.baobbhList">{{ item }}</tr>
        </div>
      </div>
      <div class="threeTopBox">
        <div class="left-border">
          <div class="box-title">检测单位名称：</div>
          <div class>{{ form.jiancdwmc }}</div>
        </div>
        <div class="right-border">
          <span>记录编号：</span>
          <span class="placeholder">{{ form.jilbh }}</span>
        </div>
      </div>
      <!-- .........................1111111111111111111111111111111......................................................... -->
      <div class="table-border">
        <table height="220px" class="top-table">
          <tbody>
            <tr>
              <td height="30" align="center" width="15%">
                <span style="width: 90px; display: inline-block">工程名称</span>
              </td>
              <td width="35%" class="text-center">
                <span>{{ form.gongcmc }}</span>
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">工程部位/用途</span>
              </td>
              <td width="35%" class="text-center">
                <span>{{ form.gongcbwyt }}</span>
              </td>
            </tr>
            <tr>
              <td height="50" align="center">样品信息</td>
              <td class="specimen-border" colspan="3">
                <span>样品名称：</span>
                <span :class="{ 'placeholder': !form.yangpmc }">{{ form.yangpmc }}</span>
                <span>；样品编号：</span>
                <span :class="{ 'placeholder-long': !form.yangpbh }">{{ form.yangpbh }}</span>

                <span>；样品数量：</span>
                <span :class="{ 'placeholder': !form.yangpsl }">{{ form.yangpsl }}</span>
                <span>；样品状态：</span>
                <span :class="{ 'placeholder': !form.yangpzt }">{{ form.yangpzt }}</span>
                <span>；来样时间：</span>
                <span :class="{ 'placeholder': !form.yangpsj }">{{ form.yangpsj }}</span>
              </td>
            </tr>
            <tr>
              <td height="25" align="center" width="15%">
                <span style="width:90px;display:inline-block">试验检测日期</span>
              </td>
               <!-- <td width="35%" class="text-center">{{ form.shiyjcrq }}</td> -->                                            
 <td width="35%" class="text-center">
      <el-input v-model="form.shiyjcrq" />
</td>
              <td align="center" width="15%">
                <span style="width:90px;display:inline-block">试验条件</span>
              </td>
              <td v-if="isPdf" width="35%">
                温度：
                <span style="display: inline-block; width: 10%;">{{ form.shiytjwd }}</span>
                ℃；湿度：
                <span style="display: inline-block; width: 10%;">{{ form.shiytjsd }}</span>%RH
              </td>
              <td v-else width="35%">
                温度：
                <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shiytjwd" class="height100"
                  style="width: 15%" />℃；湿度：
                <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shiytjsd" class="height100"
                  style="width: 15%" />%RH
              </td>
            </tr>
            <tr>
              <td height="40" align="center" width="15%">
                <span style="width: 90px; display: inline-block">检测依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.jiancyj }}</span>
                <el-input v-else type="textarea" v-model="form.jiancyj" :rows="2" class="mark"
                  @dblclick.native="showBsJiancyjView" readonly />
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">判定依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.pandyj }}</span>
                <el-input v-else type="textarea" v-model="form.pandyj" :rows="2" @dblclick.native="showBsJudgeBaseView"
                  @focus="handleFocus('pandyj')" class="mark" />
              </td>
            </tr>
            <tr class="bottom-border">
              <td height="50" align="center">
                <div>主要仪器设备</div>
                <div>名称及编号</div>
              </td>
              <td colspan="3">
                <span v-if="isPdf">{{ form.zhuyyqsbmcjbh }}</span>
                <el-input v-else type="textarea" :rows="2" v-model="form.zhuyyqsbmcjbh" class="height100 width100 mark"
                  @dblclick.native="showBsInstrumentView" readonly></el-input>
              </td>
            </tr>
          </tbody>
        </table>
        <!-- .................................22222222222222222222222222222222............................................... -->
        <table height="60px" class="middle-table">
          <tbody>
          <tr>
            <td height="30" align="center" width="15%" colspan="3">
              <span style="width: 90px; display: inline-block">取样地点</span>
            </td>
            <td width="35%" colspan="3">
              <el-input tabindex="200" v-model="form.quydd" />
            </td>
            <td align="center" width="15%" colspan="3">
              <span style="width: 90px; display: inline-block">乳化沥青品种及代号</span>
            </td>
            <td width="35%" colspan="3">
              <el-input tabindex="200" v-model="form.ruhlqpzdh" />
            </td>
          </tr>
          <tr>
            <td height="30" align="center" width="15%" colspan="3">
              <span style="width: 90px; display: inline-block">基质沥青产地</span>
            </td>
            <td width="35%" colspan="3">
              <el-input tabindex="200" v-model="form.ruhlqcd" />
            </td>
            <td align="center" width="15%" colspan="3">
              <span style="width: 90px; display: inline-block">基质沥青种类及标号</span>
            </td>
            <td width="35%" colspan="3">
              <el-input tabindex="200" v-model="form.ruhlqzlbh" />
            </td>
          </tr>
          </tbody>
        </table>
        <!-- .................................22222222222222222222222222222222............................................... -->
        <table height="548px" class="middle-table">
          <tbody>
          <tr>
            <td colspan="12">乳化沥青储存稳定性试验</td>
          </tr>
          <tr>
            <td width="5%">试验次数</td>
            <td>部位</td>
            <td>容器及玻璃棒质量（g）</td>
            <td>容器+玻璃棒+试样质量（g）</td>
            <td>试样质量(g)</td>
            <td>容器+玻璃棒+残留物质量（g）</td>
            <td>残留物质量（g）</td>
            <td colspan="2">残留物含量（%）</td>
            <td colspan="2">储存稳定 bv性测值（%）</td>
            <td>储存稳定性(%)</td>
          </tr>
          <tr>
            <td rowspan="2">{{form.wendxSycs1}}</td>
            <td>{{form.wendxBw1}}</td>
            <td>
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.wendxM11" @blur="calcWd(1, 1)" />
            </td>
            <td>
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.wendxM21" @blur="calcWd(1, 1)" />
            </td>
            <td>
              {{form.wendxM31}}
            </td>
            <td>
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.wendxM41" @blur="calcWd(1, 1)" />
            </td>
            <td>
              {{form.wendxM51}}
            </td>
            <td colspan="2">
              {{form.wendxClwhl1}}
            </td>
            <td colspan="2" rowspan="2">
              {{form.wendxCz1}}
            </td>
            <td rowspan="4">
              {{form.wendxPjz}}
            </td>
          </tr>
          <tr>
            <td>{{form.wendxBw2}}</td>
            <td>
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.wendxM12" @blur="calcWd(2, 1)" />
            </td>
            <td>
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.wendxM22" @blur="calcWd(2, 1)" />
            </td>
            <td>
              {{form.wendxM32}}
            </td>
            <td>
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.wendxM42" @blur="calcWd(2, 1)" />
            </td>
            <td>
              {{form.wendxM52}}
            </td>
            <td colspan="2">
              {{form.wendxClwhl2}}
            </td>
          </tr>
          <tr>
            <td rowspan="2">{{form.wendxSycs2}}</td>
            <td>{{form.wendxBw3}}</td>
            <td>
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.wendxM13" @blur="calcWd(3, 2)" />
            </td>
            <td>
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.wendxM23" @blur="calcWd(3, 2)" />
            </td>
            <td>
              {{form.wendxM33}}
            </td>
            <td>
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.wendxM43" @blur="calcWd(3, 2)" />
            </td>
            <td>
              {{form.wendxM53}}
            </td>
            <td colspan="2">
              {{form.wendxClwhl3}}
            </td>
            <td colspan="2" rowspan="2">
              {{form.wendxCz3}}
            </td>
          </tr>
          <tr>
            <td>{{form.wendxBw4}}</td>
            <td>
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.wendxM14" @blur="calcWd(4, 2)" />
            </td>
            <td>
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.wendxM24" @blur="calcWd(4, 2)" />
            </td>
            <td>
              {{form.wendxM34}}
            </td>
            <td>
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.wendxM44" @blur="calcWd(4, 2)" />
            </td>
            <td>
              {{form.wendxM54}}
            </td>
            <td colspan="2">
              {{form.wendxClwhl4}}
            </td>
          </tr>
          <tr>
            <td colspan="2">储存时间</td>
            <td colspan="2">第一天</td>
            <td colspan="2">第二天</td>
            <td colspan="2">第三天</td>
            <td colspan="2">第四天</td>
            <td colspan="2">第五天</td>
          </tr>
          <tr>
            <td colspan="2">温度范围℃</td>
            <td colspan="2">
              <el-input tabindex="200" v-model="form.wendfw1" />
            </td>
            <td colspan="2">
              <el-input tabindex="200" v-model="form.wendfw2" />
            </td>
            <td colspan="2">
              <el-input tabindex="200" v-model="form.wendfw3" />
            </td>
            <td colspan="2">
              <el-input tabindex="200" v-model="form.wendfw4" />
            </td>
            <td colspan="2">
              <el-input tabindex="200" v-model="form.wendfw5" />
            </td>
          </tr>
          <tr>
            <td colspan="12">乳化沥青破乳速度试验</td>
          </tr>
          <tr>
            <td>组别</td>
            <td>矿料质量（g）</td>
            <td colspan="2">外加水量（mL）</td>
            <td colspan="2">乳液用量（g）</td>
            <td colspan="2">矿料拌和结果描述</td>
            <td colspan="2">破乳速度</td>
            <td colspan="2">破乳速度分级和代号</td>
          </tr>
          <tr>
            <td>
              {{form.porsdZb1}}
            </td>
            <td colspan="1">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.porsdZl1" />
            </td>
            <td colspan="2">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.porsdSl1" />
            </td>
            <td colspan="2">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.porsdYl1" />
            </td>
            <td colspan="2">
              <el-input tabindex="200" v-model="form.porsdMs1" />
            </td>
            <td colspan="2">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.porsdSd1" />
            </td>
            <td colspan="2" rowspan="2">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.porsdPjz" @blur="setVal(form.porsdPjz)" />
            </td>
          </tr>
          <tr>
            <td>
              {{form.porsdZb2}}
            </td>
            <td colspan="1">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.porsdZl2" />
            </td>
            <td colspan="2">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.porsdSl2" />
            </td>
            <td colspan="2">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.porsdYl2" />
            </td>
            <td colspan="2">
              <el-input tabindex="200" v-model="form.porsdMs2" />
            </td>
            <td colspan="2">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.porsdSd2" />
            </td>
          </tr>
          </tbody>
        </table>
        <!-- .....................................................33333333333333333................................................... -->
        <table height="60px" class="bottom-table">
          <tr>
            <td>
              <span v-if="isPdf" class="textarea-span">{{ form.fujsm }}</span>
              <el-input v-else type="textarea" :rows="2" v-model="form.fujsm" @focus="handleFocus('fujsm')" />
            </td>
          </tr>
        </table>
      </div>
      <!-- .................................44444444444............................................. -->
      <table height="22px" class="transparent">
        <tbody>
          <tr>
            <td width="10%" align="right">检测：</td>
            <td width="15%" align="left">
              <!-- {{this.form.jiancr}} -->
            </td>
            <td width="10%" align="right">记录：</td>
            <td width="15%" align="left">
              <!-- {{this.form.jilr}} -->
            </td>
            <td width="10%" align="right">复核：</td>
            <td align="left" width="15%">
              <!-- {{this.form.fuhr}} -->
            </td>
            <td width="10%">日期：</td>
            <td align="left" width="15%">
              <div style="display: inline-block; margin-right: 30px;">年</div>
              <div style="display: inline-block; margin-right: 30px;">月</div>
              <div style="display: inline-block;">日</div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <bs-instrument-view ref="bsInstrumentViewRef" @select="selectInstrument"></bs-instrument-view>
    <bs-jiancyj-view ref="bsJiancyjViewRef" @select="selectJiancyj" :syType="syType"></bs-jiancyj-view>
    <bs-judge-base-view ref="bsJudgeBaseViewRef" @select="selectJudge" :syType="syType"></bs-judge-base-view>
  </div>
</template>

<script>
import decimal from "@/utils/big-decimal";
import Bus from "@/utils/bus";
import { handleFocus, emptyConvert, calculateMeanvalue, precision0p5 } from "@/views/reportForms/utils";
import { getLqnRhlqwdxjlbBsInfo } from "@/api/report_lqn/lqn";
import BsInstrumentView from "@/views/dept/bsInstrument/BsInstrumentView.vue";
import BsJiancyjView from "@/views/sycs/bsJiancyj/BsJiancyjView.vue";
import BsJudgeBaseView from "@/views/sycs/bsJudgeBase/BsJudgeBaseView.vue";
import BaQjDetailView from "@/views/sycs/baQjDetail/BaQjDetailView.vue";
import TableLineLogChart from "@/views/reportForms/components/TableLineLogChart.vue";

export default {
  name: "rhlqwdxjlb",
  components: {
    BsInstrumentView,
    BsJiancyjView,
    BsJudgeBaseView,
    BaQjDetailView,
    TableLineLogChart
  },
  props: {
    excelId: {
      type: [String, Number],
      default: () => ""
    },
    syType: {
      type: [String, Number],
      default: () => ""
    },
    page: {
      type: Number,
      default: () => 0
    },
    isPdf: {
      type: Boolean,
      default: () => false
    },
    printEmpty: {
      type: Boolean,
      default: () => false
    }
  },
  data () {
    return {
      form: {
        detailList: [],
        baobbhList: []
      },
      show: false
    };
  },

  watch: {
    isPdf (newVal, oldVal) {
      this.form = { ...emptyConvert(this.form, newVal) };
    }
  },
  created () {
    this.init();
  },
  methods: {
    // 根据报表id获取当前报表信息
    init () {
      this.show = false;
      getLqnRhlqwdxjlbBsInfo(this.excelId || this.$defaultExcelId).then((response) => {
        this.form = response.data;
        this.setInitialValue();
        if (!this.form.detailList || this.form.detailList.length <= 0) {
          this.getDetailList();
        }
        this.show = true;
        if (!this.form.fujsm) {
          this.form.fujsm = "附加声明：";
        }
      });
    },
    // 设置初始值
    setInitialValue () {
      if (this.form) {
        this.form.baobmc = this.form.baobmc || "乳化沥青储存稳定性、破乳速度试验检测记录表（一）";
        this.form.baobbh = this.form.baobbh || "JGLQ10019,JGLQ10021";
        this.$set(this.form, "baobbhList", []);
        this.form.baobbhList = ["JGLQ10019", "JGLQ10021"];
        this.form.wendxSycs1 = this.form.wendxSycs1 || '1';
        this.form.wendxSycs2 = this.form.wendxSycs2 || '2';
        this.form.porsdZb1 = this.form.porsdZb1 || 'A';
        this.form.porsdZb2 = this.form.porsdZb2 || 'B';
        this.form.wendxBw1 = this.form.wendxBw1 || '上PA';
        this.form.wendxBw2 = this.form.wendxBw2 || '下PB';
        this.form.wendxBw3 = this.form.wendxBw3 || '上PA';
        this.form.wendxBw4 = this.form.wendxBw4 || '下PB';
      }
    },
    getDetailList () {
      this.$set(this.form, "detailList", []);
    },
    // 显示检测依据列表
    showBsJiancyjView () {
      this.$refs.bsJiancyjViewRef.init(this.form.jiancyjIds);
    },
    // 检测依据选择
    selectJiancyj (info) {
      this.form.jiancyj = info.label;
      this.form.jiancyjIds = info.ids;
      // Bus.$emit("setKfBgJiancyj", { jiancyj: this.form.jiancyj, jiancyjIds: this.form.jiancyjIds });
    },
    // 显示判定依据列表
    showBsJudgeBaseView () {
      this.$refs.bsJudgeBaseViewRef.init(this.form.pandyjIds);
    },
    // 判断依据选择
    selectJudge (info) {
       this.form.pandyjIds = info.ids;
      this.form.pandyj = info.label;
    },
    // 显示仪器列表
    showBsInstrumentView () {
      this.$refs.bsInstrumentViewRef.init(this.form.shebIds);
    },
    // 仪器选择
    selectInstrument (info) {
      this.form.zhuyyqsbmcjbh = info.label;
      this.form.shebIds = info.ids;
      // Bus.$emit("setKfBgZhuyyqsbmcjbh", { zhuyyqsbmcjbh: this.form.zhuyyqsbmcjbh, shebIds: this.form.shebIds });
    },
    submitForm () {
      return this.form;
    },
    handleFocus (event) {
      handleFocus(event, this.page, this.form[event]);
    },
    // 稳定性试验质量计算
    calcWd(item, type) {
      // wendxM11  wendxM21  wendxM31  wendxM41   wendxM51   wendxClwhl1   wendxCz1   wendxPjz
      if (this.form['wendxM1'+item] && this.form['wendxM2'+item]) {
        const a = decimal.subtract(this.form['wendxM2'+item], this.form['wendxM1'+item]);
        this.form['wendxM3'+item] = a;
      } else {
        this.form['wendxM3'+item] = null;
      }

      if (this.form['wendxM1'+item] && this.form['wendxM4'+item]) {
        const a = decimal.subtract(this.form['wendxM4'+item], this.form['wendxM1'+item]);
        this.form['wendxM5'+item] = a;
      } else {
        this.form['wendxM5'+item] = null;
      }

      if (this.form['wendxM5'+item] && this.form['wendxM3'+item] && this.form['wendxM3'+item] != 0) {
        const a = decimal.multiply(100, this.form['wendxM5'+item]);
        const b = decimal.divide(a, this.form['wendxM3'+item]);
        this.form['wendxClwhl'+item] = b;
      } else {
        this.form['wendxClwhl'+item] = null;
      }

      if (type == 1) {
        if (this.form['wendxClwhl1'] && this.form['wendxClwhl2']) {
          const a = decimal.subtract(this.form['wendxClwhl2'], this.form['wendxClwhl1']);
          this.form['wendxCz'+item] = a;
        } else {
          this.form['wendxCz'+item] = null;
        }
      }

      if (type == 2) {
        if (this.form['wendxClwhl3'] && this.form['wendxClwhl4']) {
          const a = decimal.subtract(this.form['wendxClwhl4'], this.form['wendxClwhl3']);
          this.form['wendxCz'+item] = a;
        } else {
          this.form['wendxCz'+item] = null;
        }
      }

      if (this.form['wendxCz1'] && this.form['wendxCz3']) {
        const a = decimal.add(this.form['wendxCz1'], this.form['wendxCz3']);
        const b = decimal.divide(a, 2);
        this.form.wendxPjz = b;
      } else {
        this.form.wendxPjz = null;
      }

    },
    // 破乳速度
    setVal(val) {
      Bus.$emit("setLqnBgJiancjg", [
        { key: 198, value: val }, // 破乳速度
      ]);

    },
  }
};
</script>

<style scoped></style>
